package com.laputacastle.dr.mapper;

import com.laputacastle.dr.model.DemoRecord;
import org.apache.ibatis.jdbc.SQL;

public class DemoRecordSqlProvider {

    public String insertSelective(DemoRecord record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("t_dr_demorecord");
        
        if (record.getCId() != null) {
            sql.VALUES("c_id", "#{cId,jdbcType=VARCHAR}");
        }

        if (record.getCTitle() != null) {
            sql.VALUES("c_title", "#{cTitle,jdbcType=VARCHAR}");
        }

        if (record.getNCode() != null) {
            sql.VALUES("n_code", "#{nCode,jdbcType=INTEGER}");
        }

        if (record.getDtCreateTime() != null) {
            sql.VALUES("dt_create_time", "#{dtCreateTime,jdbcType=TIMESTAMP}");
        }

        if (record.getDtUpdateTime() != null) {
            sql.VALUES("dt_update_time", "#{dtUpdateTime,jdbcType=TIMESTAMP}");
        }

        if (record.getCDemoMd() != null) {
            sql.VALUES("c_demo_md", "#{cDemoMd,jdbcType=LONGVARCHAR}");
        }

        if (record.getCDemoHtml() != null) {
            sql.VALUES("c_demo_html", "#{cDemoHtml,jdbcType=LONGVARCHAR}");
        }

        return sql.toString();
    }

    public String updateByPrimaryKeySelective(DemoRecord record) {
        SQL sql = new SQL();
        sql.UPDATE("t_dr_demorecord");

        if (record.getCTitle() != null) {
            sql.SET("c_title = #{cTitle,jdbcType=VARCHAR}");
        }
        if (record.getNCode() != null) {
            sql.SET("n_code = #{nCode,jdbcType=INTEGER}");
        }

        if (record.getDtCreateTime() != null) {
            sql.SET("dt_create_time = #{dtCreateTime,jdbcType=TIMESTAMP}");
        }

        if (record.getDtUpdateTime() != null) {
            sql.SET("dt_update_time = #{dtUpdateTime,jdbcType=TIMESTAMP}");
        }

        if (record.getCDemoMd() != null) {
            sql.SET("c_demo_md = #{cDemoMd,jdbcType=LONGVARCHAR}");
        }

        if (record.getCDemoHtml() != null) {
            sql.SET("c_demo_html = #{cDemoHtml,jdbcType=LONGVARCHAR}");
        }
        
        sql.WHERE("c_id = #{cId,jdbcType=VARCHAR}");
        
        return sql.toString();
    }
}